
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <title>调和单个节点 · React源码解析</title>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.0">
        
        
        
    
    <link rel="stylesheet" href="../../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-theme-api/theme-api.css">
                
            
        

    

    
        
        <link rel="stylesheet" href="../../../styles/website.css">
        
    
        
    
        
    
        
    
        
    
        
    

         
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="array.html" />
    
    
    <link rel="prev" href="../reconcile-children.html" />
    

<script
  async
  src="https://www.googletagmanager.com/gtag/js?id=UA-49483742-5"
></script>
<script>
  window.dataLayer = window.dataLayer || []
  function gtag() {
    dataLayer.push(arguments)
  }
  gtag('js', new Date())

  gtag('config', 'UA-49483742-5')
</script>

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../../">
            
                <a href="../../../">
            
                    
                    首页
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" >
            
                <span>
            
                    
                    基础
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../../api/react.html">
            
                <a href="../../api/react.html">
            
                    
                    React API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../../api/react-element.html">
            
                <a href="../../api/react-element.html">
            
                    
                    ReactElement
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../../api/react-children.html">
            
                <a href="../../api/react-children.html">
            
                    
                    React Children
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../../api/react-structure.html">
            
                <a href="../../api/react-structure.html">
            
                    
                    React 中的数据结构
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" >
            
                <span>
            
                    
                    创建更新
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../../update/react-dom-render.html">
            
                <a href="../../update/react-dom-render.html">
            
                    
                    ReactDOM.render
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../../update/set-state.html">
            
                <a href="../../update/set-state.html">
            
                    
                    setState & forceUpdate
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../../update/expiration-time.html">
            
                <a href="../../update/expiration-time.html">
            
                    
                    expirationTime 计算
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" >
            
                <span>
            
                    
                    任务调度
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../scheduler-global.html">
            
                <a href="../scheduler-global.html">
            
                    
                    全局变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../schedule-work.html">
            
                <a href="../schedule-work.html">
            
                    
                    scheduleWork
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../scheduler-pkg.html">
            
                <a href="../scheduler-pkg.html">
            
                    
                    react-scheduler
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../perform-work.html">
            
                <a href="../perform-work.html">
            
                    
                    performWork
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../perform-unit-of-work.html">
            
                <a href="../perform-unit-of-work.html">
            
                    
                    performUnitOfWork
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="../render-root.html">
            
                <a href="../render-root.html">
            
                    
                    renderRoot
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.6.1" data-path="../render-root/throw-exception.html">
            
                <a href="../render-root/throw-exception.html">
            
                    
                    throwException
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="../begin-work.html">
            
                <a href="../begin-work.html">
            
                    
                    beginWork
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.7.1" data-path="../begin-work/mount-indeterminate-component.html">
            
                <a href="../begin-work/mount-indeterminate-component.html">
            
                    
                    mountIndeterminateComponent
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.2" data-path="../begin-work/mount-lazy-component.html">
            
                <a href="../begin-work/mount-lazy-component.html">
            
                    
                    mountLazyComponent
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.3" data-path="../begin-work/update-functional-component.html">
            
                <a href="../begin-work/update-functional-component.html">
            
                    
                    updateFunctionalComponent
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.4" data-path="../begin-work/update-class-component.html">
            
                <a href="../begin-work/update-class-component.html">
            
                    
                    updateClassComponent
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.5" data-path="../begin-work/update-host-root.html">
            
                <a href="../begin-work/update-host-root.html">
            
                    
                    updateHostRoot
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.6" data-path="../begin-work/update-host-component.html">
            
                <a href="../begin-work/update-host-component.html">
            
                    
                    updateHostComponent
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.7" data-path="../begin-work/update-host-text.html">
            
                <a href="../begin-work/update-host-text.html">
            
                    
                    updateHostText
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.8" data-path="../../feature/Suspense-component.md">
            
                <span>
            
                    
                    updateSuspenseComponent
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.9" data-path="../begin-work/update-portal-component.html">
            
                <a href="../begin-work/update-portal-component.html">
            
                    
                    updatePortalComponent
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.10" data-path="../begin-work/update-forward-ref.html">
            
                <a href="../begin-work/update-forward-ref.html">
            
                    
                    updateForwardRef
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.11" data-path="../begin-work/update-fragment.html">
            
                <a href="../begin-work/update-fragment.html">
            
                    
                    updateFragment
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.12" data-path="../begin-work/update-mode.html">
            
                <a href="../begin-work/update-mode.html">
            
                    
                    updateMode
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.13" data-path="../begin-work/update-profiler.html">
            
                <a href="../begin-work/update-profiler.html">
            
                    
                    updateProfiler
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.14" data-path="../begin-work/update-context-provider.html">
            
                <a href="../begin-work/update-context-provider.html">
            
                    
                    updateContextProvider
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.15" data-path="../begin-work/update-context-consumer.html">
            
                <a href="../begin-work/update-context-consumer.html">
            
                    
                    updateContextConsumer
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.8" data-path="../reconcile-children.html">
            
                <a href="../reconcile-children.html">
            
                    
                    reconcileChildren
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.4.8.1" data-path="single.html">
            
                <a href="single.html">
            
                    
                    调和单个节点
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.8.2" data-path="array.html">
            
                <a href="array.html">
            
                    
                    调和列表
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" >
            
                <span>
            
                    
                    commit 阶段
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../../commit-phase/commit-root.html">
            
                <a href="../../commit-phase/commit-root.html">
            
                    
                    commitRoot
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../../commit-phase/invokeGuardedCallback.html">
            
                <a href="../../commit-phase/invokeGuardedCallback.html">
            
                    
                    invokeGuardedCallback
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../../commit-phase/commitBeforeMutationLifecycles.html">
            
                <a href="../../commit-phase/commitBeforeMutationLifecycles.html">
            
                    
                    commitBeforeMutationLifecycles
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../../commit-phase/commit-all-host-effects.html">
            
                <a href="../../commit-phase/commit-all-host-effects.html">
            
                    
                    commitAllHostEffects
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.4.1" data-path="../../commit-phase/host-effects/CommitPlacement.html">
            
                <a href="../../commit-phase/host-effects/CommitPlacement.html">
            
                    
                    commitPlacement
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4.2" data-path="../../commit-phase/host-effects/CommitWork.html">
            
                <a href="../../commit-phase/host-effects/CommitWork.html">
            
                    
                    commitWork
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4.3" data-path="../../commit-phase/host-effects/CommitDeletion.html">
            
                <a href="../../commit-phase/host-effects/CommitDeletion.html">
            
                    
                    commitDeletion
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="../../commit-phase/commit-all-lifecycles.html">
            
                <a href="../../commit-phase/commit-all-lifecycles.html">
            
                    
                    commitAllLifecycle
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" >
            
                <span>
            
                    
                    功能
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../../features/context.html">
            
                <a href="../../features/context.html">
            
                    
                    context
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../../features/hydrate.html">
            
                <a href="../../features/hydrate.html">
            
                    
                    hydrate
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../../features/ref.html">
            
                <a href="../../features/ref.html">
            
                    
                    ref
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../../features/event-injection.html">
            
                <a href="../../features/event-injection.html">
            
                    
                    事件系统初始化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../../features/event-bind.html">
            
                <a href="../../features/event-bind.html">
            
                    
                    事件绑定
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="../../features/event-dispatch.html">
            
                <a href="../../features/event-dispatch.html">
            
                    
                    事件触发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="../../features/event-create-event-object.html">
            
                <a href="../../features/event-create-event-object.html">
            
                    
                    事件对象生成
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.8" data-path="../../features/Suspense-component.html">
            
                <a href="../../features/Suspense-component.html">
            
                    
                    Suspense
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.9" data-path="../../features/suspense.html">
            
                <a href="../../features/suspense.html">
            
                    
                    挂起任务的含义
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.10" data-path="../../features/suspense-lazy.html">
            
                <a href="../../features/suspense-lazy.html">
            
                    
                    lazy 组件
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" >
            
                <span>
            
                    
                    Hooks
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../../hooks/hooks-start.html">
            
                <a href="../../hooks/hooks-start.html">
            
                    
                    开始
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../../hooks/hooks-use-state.html">
            
                <a href="../../hooks/hooks-use-state.html">
            
                    
                    useState
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../../hooks/hooks-use-effect.html">
            
                <a href="../../hooks/hooks-use-effect.html">
            
                    
                    useEffect
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="../../hooks/hooks-others.html">
            
                <a href="../../hooks/hooks-others.html">
            
                    
                    其他API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.5" data-path="../../hooks/hooks-common.html">
            
                <a href="../../hooks/hooks-common.html">
            
                    
                    通用API
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <form
            action="https://buttondown.email/api/emails/embed-subscribe/Jokcy"
            method="post"
            target="popupwindow"
            onsubmit="window.open('https://buttondown.email/Jokcy', 'popupwindow')"
            class="buttondown-form"
            >
            <input type="email" name="email" id="bd-email" placeholder="(your@email.com)">
            <input type="hidden" value="1" name="embed"/>
            <button type="submit">订阅我</button>
        </form>
    </li>
</ul>

                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                 
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../../.." >调和单个节点</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div class="api-method"><div class="api-method-definition"><h1 id="reconcilesingleelement">reconcileSingleElement</h1><p>&#x7B2C;&#x4E00;&#x4E2A;<code>while</code>&#x5FAA;&#x73AF;&#x7684;&#x76EE;&#x7684;&#x660E;&#x663E;&#x5C31;&#x662F;&#x627E;&#x5230;&#x8001;&#x7684;<code>children</code>&#x548C;&#x65B0;&#x7684;<code>children</code>&#x4E2D;&#x7B2C;&#x4E00;&#x4E2A;<strong><code>key</code>&#x548C;&#x8282;&#x70B9;&#x7C7B;&#x578B;</strong>&#x76F8;&#x540C;&#x7684;&#x8282;&#x70B9;&#xFF0C;&#x76F4;&#x63A5;&#x590D;&#x7528;&#x8FD9;&#x4E2A;&#x8282;&#x70B9;&#xFF0C;&#x7136;&#x540E;&#x5220;&#x9664;&#x8001;&#x7684;<code>children</code>&#x4E2D;&#x5176;&#x4ED6;&#x7684;&#xFF08;&#x6211;&#x4EEC;&#x65E0;&#x6CD5;&#x4FDD;&#x8BC1;&#x65B0;&#x7684;<code>children</code>&#x662F;&#x5355;&#x4E2A;&#x8282;&#x70B9;&#x7684;&#x65F6;&#x5019;&#x8001;&#x7684;<code>children</code>&#x4E5F;&#x662F;&#x5355;&#x4E2A;&#x7684;&#xFF0C;&#x6240;&#x4EE5;&#x8981;&#x7528;&#x904D;&#x5386;&#x3002;&#xFF09;</p><p><strong>&#x6CE8;&#x610F;<code>key</code>&#x4E3A;<code>null</code>&#x6211;&#x4EEC;&#x4E5F;&#x8BA4;&#x4E3A;&#x662F;&#x76F8;&#x7B49;&#xFF0C;&#x56E0;&#x4E3A;&#x5355;&#x4E2A;&#x8282;&#x70B9;&#x6CA1;&#x6709;<code>key</code>&#x4E5F;&#x662F;&#x6B63;&#x5E38;&#x7684;</strong></p><p>&#x5982;&#x679C;&#x627E;&#x4E86;&#x4E00;&#x5708;&#x6CA1;&#x53D1;&#x73B0;&#xFF0C;&#x90A3;&#x4E48;&#x5C31;&#x628A;&#x8001;&#x7684;<code>children</code>&#x90FD;&#x5220;&#x4E86;&#xFF0C;&#x91CD;&#x65B0;&#x4E3A;&#x65B0;&#x7684;<code>children</code>&#x521B;&#x5EFA;&#x8282;&#x70B9;&#x3002;</p><p><code>coerceRef</code>&#x7684;&#x4F5C;&#x7528;&#x662F;&#x628A;&#x89C4;&#x8303;&#x5316;<code>ref</code>&#xFF0C;&#x56E0;&#x4E3A;<code>ref</code>&#x6709;&#x4E09;&#x79CD;&#x5F62;&#x5F0F;&#xFF0C;<code>string ref</code>&#x8981;&#x8F6C;&#x6362;&#x6210;&#x65B9;&#x6CD5;&#x3002;</p><pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">coerceRef</span>(<span class="hljs-params">
  returnFiber: Fiber,
  current: Fiber | null,
  element: ReactElement,
</span>) </span>{
  <span class="hljs-keyword">let</span> mixedRef = element.ref
  <span class="hljs-keyword">if</span> (
    mixedRef !== <span class="hljs-literal">null</span> &amp;&amp;
    <span class="hljs-keyword">typeof</span> mixedRef !== <span class="hljs-string">&apos;function&apos;</span> &amp;&amp;
    <span class="hljs-keyword">typeof</span> mixedRef !== <span class="hljs-string">&apos;object&apos;</span>
  ) {
    <span class="hljs-keyword">if</span> (element._owner) {
      <span class="hljs-keyword">const</span> owner: ?Fiber = (element._owner: any)
      <span class="hljs-keyword">let</span> inst
      <span class="hljs-keyword">if</span> (owner) {
        <span class="hljs-keyword">const</span> ownerFiber = ((owner: any): Fiber)
        invariant(
          ownerFiber.tag === ClassComponent,
          <span class="hljs-string">&apos;Function components cannot have refs.&apos;</span>,
        )
        inst = ownerFiber.stateNode
      }
      invariant(
        inst,
        <span class="hljs-string">&apos;Missing owner for string ref %s. This error is likely caused by a &apos;</span> +
          <span class="hljs-string">&apos;bug in React. Please file an issue.&apos;</span>,
        mixedRef,
      )
      <span class="hljs-keyword">const</span> stringRef = <span class="hljs-string">&apos;&apos;</span> + mixedRef
      <span class="hljs-comment">// Check if previous string ref matches new string ref</span>
      <span class="hljs-keyword">if</span> (
        current !== <span class="hljs-literal">null</span> &amp;&amp;
        current.ref !== <span class="hljs-literal">null</span> &amp;&amp;
        <span class="hljs-keyword">typeof</span> current.ref === <span class="hljs-string">&apos;function&apos;</span> &amp;&amp;
        current.ref._stringRef === stringRef
      ) {
        <span class="hljs-keyword">return</span> current.ref
      }
      <span class="hljs-keyword">const</span> ref = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">value</span>) </span>{
        <span class="hljs-keyword">let</span> refs = inst.refs
        <span class="hljs-keyword">if</span> (refs === emptyRefsObject) {
          <span class="hljs-comment">// This is a lazy pooled frozen object, so we need to initialize.</span>
          refs = inst.refs = {}
        }
        <span class="hljs-keyword">if</span> (value === <span class="hljs-literal">null</span>) {
          <span class="hljs-keyword">delete</span> refs[stringRef]
        } <span class="hljs-keyword">else</span> {
          refs[stringRef] = value
        }
      }
      ref._stringRef = stringRef
      <span class="hljs-keyword">return</span> ref
    } <span class="hljs-keyword">else</span> {
      <span class="hljs-comment">// error handlers</span>
    }
  }
  <span class="hljs-keyword">return</span> mixedRef
}</code></pre>
<p>&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x53EF;&#x4EE5;&#x770B;&#x51FA;&#x6765;&#x4F1A;&#x628A;<code>string ref</code>&#x8F6C;&#x6362;&#x6210;&#x4E00;&#x4E2A;&#x65B9;&#x6CD5;&#xFF0C;&#x6700;&#x7EC8;&#x4F1A;&#x628A;&#x5BF9;&#x8C61;&#x8BBE;&#x7F6E;&#x5230;<code>inst.refs</code>&#x4E0A;&#x3002;</p></div><div class="api-method-code"><div class="api-method-sample" data-lang="js" data-name="JavaScript"><pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">reconcileSingleElement</span>(<span class="hljs-params">
  returnFiber: Fiber,
  currentFirstChild: Fiber | null,
  element: ReactElement,
  expirationTime: ExpirationTime,
</span>): <span class="hljs-title">Fiber</span> </span>{
  <span class="hljs-keyword">const</span> key = element.key
  <span class="hljs-keyword">let</span> child = currentFirstChild
  <span class="hljs-keyword">while</span> (child !== <span class="hljs-literal">null</span>) {
    <span class="hljs-comment">// <span class="hljs-doctag">TODO:</span> If key === null and child.key === null, then this only applies to</span>
    <span class="hljs-comment">// the first item in the list.</span>
    <span class="hljs-keyword">if</span> (child.key === key) {
      <span class="hljs-keyword">if</span> (
        child.tag === Fragment
          ? element.type === REACT_FRAGMENT_TYPE
          : child.elementType === element.type
      ) {
        deleteRemainingChildren(returnFiber, child.sibling)
        <span class="hljs-keyword">const</span> existing = useFiber(
          child,
          element.type === REACT_FRAGMENT_TYPE
            ? element.props.children
            : element.props,
          expirationTime,
        )
        existing.ref = coerceRef(returnFiber, child, element)
        existing.return = returnFiber
        <span class="hljs-keyword">if</span> (__DEV__) {
          existing._debugSource = element._source
          existing._debugOwner = element._owner
        }
        <span class="hljs-keyword">return</span> existing
      } <span class="hljs-keyword">else</span> {
        deleteRemainingChildren(returnFiber, child)
        <span class="hljs-keyword">break</span>
      }
    } <span class="hljs-keyword">else</span> {
      deleteChild(returnFiber, child)
    }
    child = child.sibling
  }

  <span class="hljs-keyword">if</span> (element.type === REACT_FRAGMENT_TYPE) {
    <span class="hljs-keyword">const</span> created = createFiberFromFragment(
      element.props.children,
      returnFiber.mode,
      expirationTime,
      element.key,
    )
    created.return = returnFiber
    <span class="hljs-keyword">return</span> created
  } <span class="hljs-keyword">else</span> {
    <span class="hljs-keyword">const</span> created = createFiberFromElement(
      element,
      returnFiber.mode,
      expirationTime,
    )
    created.ref = coerceRef(returnFiber, currentFirstChild, element)
    created.return = returnFiber
    <span class="hljs-keyword">return</span> created
  }
}</code></pre>
</div></div></div>



<div class="api-method"><div class="api-method-definition"><h1 id="reconcilesingleportal">reconcileSinglePortal</h1><p><code>portal</code>&#x5176;&#x5B9E;&#x5C31;&#x662F;&#x7279;&#x6B8A;&#x7684;<code>ReactElement</code>&#xFF0C;&#x4ED6;&#x7684;<code>$$typeof</code>&#x4E0D;&#x662F;<code>REACT_ELEMENT_TYPE</code>&#x3002;&#x4F46;&#x662F;&#x4ED6;&#x4EEC;&#x7684;&#x5904;&#x7406;&#x65B9;&#x5F0F;&#x5176;&#x5B9E;&#x5DEE;&#x4E0D;&#x591A;&#xFF0C;&#x4E5F;&#x90FD;&#x662F;&#x5FAA;&#x73AF;&#x8001;&#x7684;<code>children</code>&#x627E;&#x80FD;&#x590D;&#x7528;&#x7684;&#xFF0C;&#x627E;&#x4E0D;&#x5230;&#x5C31;&#x521B;&#x5EFA;&#x65B0;&#x7684;&#xFF0C;&#x53EA;&#x662F;&#x521B;&#x5EFA;<code>Fiber</code>&#x7684;&#x65B9;&#x6CD5;&#x4E0D;&#x4E00;&#x6837;&#x3002;</p></div><div class="api-method-code"><div class="api-method-sample" data-lang="js" data-name="JavaScript"><pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">reconcileSinglePortal</span>(<span class="hljs-params">
  returnFiber: Fiber,
  currentFirstChild: Fiber | null,
  portal: ReactPortal,
  expirationTime: ExpirationTime,
</span>): <span class="hljs-title">Fiber</span> </span>{
  <span class="hljs-keyword">const</span> key = portal.key
  <span class="hljs-keyword">let</span> child = currentFirstChild
  <span class="hljs-keyword">while</span> (child !== <span class="hljs-literal">null</span>) {
    <span class="hljs-keyword">if</span> (child.key === key) {
      <span class="hljs-keyword">if</span> (
        child.tag === HostPortal &amp;&amp;
        child.stateNode.containerInfo === portal.containerInfo &amp;&amp;
        child.stateNode.implementation === portal.implementation
      ) {
        deleteRemainingChildren(returnFiber, child.sibling)
        <span class="hljs-keyword">const</span> existing = useFiber(child, portal.children || [], expirationTime)
        existing.return = returnFiber
        <span class="hljs-keyword">return</span> existing
      } <span class="hljs-keyword">else</span> {
        deleteRemainingChildren(returnFiber, child)
        <span class="hljs-keyword">break</span>
      }
    } <span class="hljs-keyword">else</span> {
      deleteChild(returnFiber, child)
    }
    child = child.sibling
  }

  <span class="hljs-keyword">const</span> created = createFiberFromPortal(
    portal,
    returnFiber.mode,
    expirationTime,
  )
  created.return = returnFiber
  <span class="hljs-keyword">return</span> created
}</code></pre>
</div></div></div>



<div class="api-method"><div class="api-method-definition"><h1 id="reconcilesingletextnode">reconcileSingleTextNode</h1><p>&#x6587;&#x5B57;&#x8282;&#x70B9;&#x7684;&#x5BF9;&#x6BD4;&#x6BD4;&#x8F83;&#x7B80;&#x5355;&#x7C97;&#x66B4;&#xFF0C;&#x76F4;&#x63A5;&#x627E;&#x8001;&#x7684;<code>children</code>&#x4E2D;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x8282;&#x70B9;&#xFF0C;&#x5982;&#x679C;&#x662F;&#x6587;&#x5B57;&#x8282;&#x70B9;&#x5C31;&#x590D;&#x7528;&#xFF0C;&#x5982;&#x679C;&#x4E0D;&#x662F;&#x5C31;&#x5220;&#x9664;&#x5168;&#x90E8;&#x8001;&#x7684;&#x8282;&#x70B9;&#xFF0C;&#x521B;&#x5EFA;&#x65B0;&#x7684;&#x6587;&#x5B57;&#x8282;&#x70B9;&#x3002;</p></div><div class="api-method-code"><div class="api-method-sample" data-lang="js" data-name="JavaScript"><pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">reconcileSingleTextNode</span>(<span class="hljs-params">
  returnFiber: Fiber,
  currentFirstChild: Fiber | null,
  textContent: string,
  expirationTime: ExpirationTime,
</span>): <span class="hljs-title">Fiber</span> </span>{
  <span class="hljs-comment">// There&apos;s no need to check for keys on text nodes since we don&apos;t have a</span>
  <span class="hljs-comment">// way to define them.</span>
  <span class="hljs-keyword">if</span> (currentFirstChild !== <span class="hljs-literal">null</span> &amp;&amp; currentFirstChild.tag === HostText) {
    <span class="hljs-comment">// We already have an existing node so let&apos;s just update it and delete</span>
    <span class="hljs-comment">// the rest.</span>
    deleteRemainingChildren(returnFiber, currentFirstChild.sibling)
    <span class="hljs-keyword">const</span> existing = useFiber(currentFirstChild, textContent, expirationTime)
    existing.return = returnFiber
    <span class="hljs-keyword">return</span> existing
  }
  <span class="hljs-comment">// The existing first child is not a text node so we need to create one</span>
  <span class="hljs-comment">// and delete the existing ones.</span>
  deleteRemainingChildren(returnFiber, currentFirstChild)
  <span class="hljs-keyword">const</span> created = createFiberFromText(
    textContent,
    returnFiber.mode,
    expirationTime,
  )
  created.return = returnFiber
  <span class="hljs-keyword">return</span> created
}</code></pre>
</div></div></div>




                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
<div id="disqus_thread"></div>
<script>
  /**
   *  RECOMMENDED CONFIGURATION VARIABLES: EDIT AND UNCOMMENT THE SECTION BELOW TO INSERT DYNAMIC VALUES FROM YOUR PLATFORM OR CMS.
   *  LEARN WHY DEFINING THESE VARIABLES IS IMPORTANT: https://disqus.com/admin/universalcode/#configuration-variables*/
  /*
var disqus_config = function () {
this.page.url = PAGE_URL;  // Replace PAGE_URL with your page's canonical URL variable
this.page.identifier = PAGE_IDENTIFIER; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
};
*/
  ;(function() {
    // DON'T EDIT BELOW THIS LINE
    var d = document,
      s = d.createElement('script')
    s.src = 'https://react-source-code.disqus.com/embed.js'
    s.setAttribute('data-timestamp', +new Date())
    ;(d.head || d.body).appendChild(s)
  })()
</script>
<noscript
  >Please enable JavaScript to view the
  <a href="https://disqus.com/?ref_noscript"
    >comments powered by Disqus.</a
  ></noscript
>

            </div>

            

        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"调和单个节点","level":"1.4.8.1","depth":3,"next":{"title":"调和列表","level":"1.4.8.2","depth":3,"path":"book/flow/reconcile-children/array.md","ref":"book/flow/reconcile-children/array.md","articles":[]},"previous":{"title":"reconcileChildren","level":"1.4.8","depth":2,"path":"book/flow/reconcile-children.md","ref":"book/flow/reconcile-children.md","articles":[{"title":"调和单个节点","level":"1.4.8.1","depth":3,"path":"book/flow/reconcile-children/single.md","ref":"book/flow/reconcile-children/single.md","articles":[]},{"title":"调和列表","level":"1.4.8.2","depth":3,"path":"book/flow/reconcile-children/array.md","ref":"book/flow/reconcile-children/array.md","articles":[]}]},"dir":"ltr"},"config":{"plugins":["theme-api"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"sharing":{"facebook":false,"twitter":false,"google":false,"weibo":true,"instapaper":false,"vk":false,"all":["weibo","google","twitter","weibo","instapaper"]},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-api":{"languages":[],"split":true,"theme":"light"},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"React源码解析","language":"zh-hans","gitbook":"*"},"file":{"path":"book/flow/reconcile-children/single.md","mtime":"2018-11-21T05:51:11.376Z","type":"markdown"},"gitbook":{"version":"3.2.0","time":"2019-07-08T12:28:32.264Z"},"basePath":"../../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../../gitbook/gitbook.js"></script>
    <script src="../../../gitbook/theme.js"></script>
    
        
        <script src="../../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-theme-api/theme-api.js"></script>
        
    

    </body>
</html>

